package n14;

public class Main {
    public static String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) {
            return "";
        }
        String common = strs[0];
        if (strs.length == 1) {
            return common;
        }
        for (int i = 1; i < strs.length; i++) {
            String str = strs[i];

            String temp = "";
            for (int j = 0; j < common.length() && j < str.length(); j++) {
                char c = common.charAt(j);
                if (c == str.charAt(j)) {
                    temp += c;
                } else {
                    break;
                }
            }

            if (temp.length() == 0) {
                return "";
            } else {
                common = temp;
            }

        }
        return common;
    }

    public static void main(String[] args) {
        String[] strs = {"flower","flow","flight"};
        // String[] strs = {"dog", "racecar", "car"};
        // String[] strs = {"dog","doga"};
        // String[] strs = {"dog"};
        System.out.println(longestCommonPrefix(strs));

    }
}
